home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST7-4.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  69 lines

  1. ;
  2. ; *** Listing 7-4 ***
  3. ;
  4. ; Adds one far array to another far array as a high-level
  5. ; language would, loading each far pointer with LES every
  6. ; time it's needed.
  7. ;
  8.     jmp    Skip
  9. ;
  10. ARRAY_LENGTH    equ    1000
  11. Array1    db    ARRAY_LENGTH dup (1)
  12. Array2    db    ARRAY_LENGTH dup (2)
  13. ;
  14. ; Adds one byte-sized array to another byte-sized array.
  15. ; C-callable.
  16. ;
  17. ; Input: parameters on stack as in AddArraysParms
  18. ;
  19. ; Output: none
  20. ;
  21. ; Registers altered: AL, BX, CX, ES
  22. ;
  23. AddArraysParms    struc
  24.     dw    ?    ;pushed BP
  25.     dw    ?    ;return address
  26. FarPtr1    dd    ?    ;pointer to array to be added to
  27. FarPtr2    dd    ?    ;pointer to array to add to the
  28.             ; other array
  29. AddArraysLength    dw ?    ;# of bytes to add
  30. AddArraysParms    ends
  31. ;
  32. AddArrays    proc    near
  33.     push    bp        ;save caller's BP
  34.     mov    bp,sp        ;point to stack frame
  35.     mov    cx,[bp+AddArraysLength]
  36.                 ;get the length to add
  37. AddArraysLoop:
  38.     les    bx,[bp+FarPtr2]    ;point to the array to add
  39.                 ; from
  40.     inc    word ptr [bp+FarPtr2]
  41.                 ;point to the next byte
  42.                 ; of the array to add from
  43.     mov    al,es:[bx]    ;get the array element to
  44.                 ; add
  45.     les    bx,[bp+FarPtr1]    ;point to the array to add
  46.                 ; to
  47.     inc    word ptr [bp+FarPtr1]
  48.                 ;point to the next byte
  49.                 ; of the array to add to
  50.     add    es:[bx],al    ;add to the array
  51.     loop    AddArraysLoop
  52.     pop    bp        ;restore caller's BP
  53.     ret
  54. AddArrays    endp
  55. ;
  56. Skip:
  57.     call    ZTimerOn
  58.     mov    ax,ARRAY_LENGTH
  59.     push    ax    ;pass the length to add
  60.     push    ds    ;pass segment of Array2
  61.     mov    ax,offset Array2
  62.     push    ax    ;pass offset of Array2
  63.     push    ds    ;pass segment of Array1
  64.     mov    ax,offset Array1
  65.     push    ax    ;pass offset of Array1
  66.     call    AddArrays
  67.     add    sp,10    ;clear the parameters
  68.     call    ZTimerOff
  69.